package com.xiaohudie.JUC;

/**
 * @Author xiao hu die
 * @Date 2022/1/15 21:06
 * @Version 1.0
 */

import lombok.SneakyThrows;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;

/**创建阻塞队列*/
public class Thread13 {
    @SneakyThrows
    public static void main(String[] args) {
        BlockingQueue<String> blockingQueue =new ArrayBlockingQueue<>(5);
     blockingQueue.add("刘碟1");
        blockingQueue.add("刘碟2");
        blockingQueue.add("刘碟3");
        blockingQueue.add("刘碟4");
        blockingQueue.add("刘碟5");
        System.out.println(blockingQueue.remove());
        System.out.println(blockingQueue.remove());
        System.out.println(blockingQueue.remove());
        System.out.println(blockingQueue.remove());
        System.out.println(blockingQueue.remove());
      blockingQueue.offer("陈唯一1");
        blockingQueue.offer("陈唯一2");
        blockingQueue.offer("陈唯一3");
        blockingQueue.offer("陈唯一4");
        blockingQueue.offer("陈唯一5");
        blockingQueue.offer("陈唯一6");
        System.out.println(blockingQueue.poll());
        System.out.println(blockingQueue.poll());
        System.out.println(blockingQueue.poll());
        System.out.println(blockingQueue.poll());
        System.out.println(blockingQueue.poll());
        System.out.println(blockingQueue.poll());
       blockingQueue.put("a");
        blockingQueue.put("a");
        blockingQueue.put("a");
        blockingQueue.put("a");
        blockingQueue.put("a");
        blockingQueue.take();
        blockingQueue.put("a");
        System.out.println(blockingQueue.offer("刘碟1"));
        System.out.println(blockingQueue.offer("刘碟2"));
        System.out.println(blockingQueue.offer("刘碟3"));
        System.out.println(blockingQueue.offer("刘碟4"));
        System.out.println(blockingQueue.offer("刘碟5"));
        System.out.println(blockingQueue.offer("刘碟", 3l, TimeUnit.SECONDS));
        System.out.println(blockingQueue.poll());
        System.out.println(blockingQueue.poll());
        System.out.println(blockingQueue.poll());
        System.out.println(blockingQueue.poll());
        System.out.println(blockingQueue.poll());
        System.out.println(blockingQueue.poll(3L,TimeUnit.SECONDS));


    }
}
